package top.xmj.controller;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.xmj.service.IMailService;
import top.xmj.vo.ResultVO;

import java.util.Date;

/**
 * 测试邮件发送
 * @author qzz
 */
@RestController
@RequestMapping("/mail")
@ApiModel("邮件发送")
public class SendMailController {

    @Autowired
    private IMailService mailService;

    /**
     * 发送文本邮件
     * @param to
     */
    @PostMapping(value ="/sendTextMail")
    @ApiOperation("发送文本邮件")
    public ResultVO sendTextMail(@RequestParam String to) {
        String code = mailService.sendTextMailMessage(to);
        if(code!=null&&code!=""){
            String res = to+(new Date()).toString();
            return new ResultVO(200,"发送成功",null);
        }
        return new ResultVO(505,"发送失败",null);
    }

    /**
     * 发送HTML邮件
     * @param to
     */
    @PostMapping("/sendHtmlMailMessage")
    @ApiOperation("发送HTML邮件")
    public ResultVO sendHtmlMailMessage(@RequestParam String to){
        String code = mailService.sendHTMlMailMessage(to);
        if(code!=null&&code!=""){
            String res = to+(new Date()).toString();
            return new ResultVO(200,"发送成功",null);
        }
        return new ResultVO(505,"发送失败",null);
    }
}

